/*
 * @Author       : 邱狮杰
 * @Date         : 2021-09-03 15:18:57
 * @LastEditTime: 2021-09-05 10:57:34
 * @FilePath: /new-hope/src/store/user.ts
 * @Description  :
 */
import { StoreOptions } from "vuex";
export interface State {
  // 奖品列表
  prizeList: {
    pic: string;
    title: string;
    type: string;
  }[];
  // user info
  userInfo: {
    address: string;
    avatar: string;
    created_at: string;
    id: string;
    ip: string;
    mainaward: string;
    needinfo: number;
    nickname: string;
    openid: string;
    phone: string;
    result: string;
    truename: string;
    value: string;
  };
  // 我的奖品
  myawards: {
    type: string;
    value: string;
  }[];
  popUpRule: boolean;
}
export const user: StoreOptions<State> & {
  namespaced: boolean;
} = {
  namespaced: true,
  state: {
    popUpRule: false,
    myawards: [],
    // @ts-ignore
    userInfo: {},
    prizeList: [],
  },
  strict: true,
  getters: {
    getMyawards(state) {
      return state.myawards;
    },
    getIsTheInformationComplete(state) {
      const r = [
        state.userInfo.address,
        state.userInfo.phone,
        state.userInfo.truename,
      ];
      return r.includes("");
    },
  },
  mutations: {
    editPopUpRule(state, playload) {
      state.popUpRule = playload;
    },
    initUserInfo(state, playload) {
      state.userInfo = playload;
    },
    initPrizeList(state, playload) {
      state.prizeList = playload;
    },
    initMyAwards(state, playload) {
      state.myawards = playload;
    },
  },
};
